package com.tunis.gtug.client;

import java.util.*;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.fx.FxConfig;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.util.Rectangle;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.user.client.Element;

public class ContentGrid extends LayoutContainer {

	public static List<Developper> models;
	
	public ContentGrid(List<Developper> models) {
		this.models = models;
	}

	public void addIntoGrid(String firstName, String lastName, String email,
			String occupation) {

		models.add(new Developper(firstName,lastName,email,occupation));
	}
	public static void addIntoGrid(Developper dev){
		models.add(dev);
		
	}

	protected void onRender(Element parent, int pos) {
		// TODO Auto-generated method stub
		super.onRender(parent, pos);
		 store = new ListStore<Developper>();
		// List<Developper> models = new ArrayList<Developper>();
		
		
		
		
		
		models.add(new Developper("Mariem", "Chater",
				"chater.mariem@gmail.com", "Ingenieur"));
		models.add(new Developper("Younes", "Ben Tlili",
				"younestlili5001@gmail.com", "Ingenieur"));
		models.add(new Developper("Mohamed", "BelHadj", "medbelh@gmail.com",
				"Etudiant"));
		models.add(new Developper("Wael", "Jouini", "jouiniwael@gmail.com",
				"Ingenieur"));
		models.add(new Developper("Fahmi", "Bedoui",
				"fahmi.bedoui87@gmail.com", "Etudiant"));
		models.add(new Developper("Wassim", "Sakly", "sakly.wassi@gmail.com",
				"Etudiant"));
		models.add(new Developper("Ramzi", "Hannachi",
				"ramzi.hannachi@gmail.com", "Ingenieur"));
		models.add(new Developper("Oussema", "Gabtni", "oussema@gmail.com",
				"Ingenieur"));
		models.add(new Developper("Hamza", "Dridi", "drid.hamza.007@gmail.com",
				"Etudiant"));
		models.add(new Developper("Mohamed Amine", "Ben Mabrouk",
				"amine.ben.mabrouk@gmail.com", "Etudiant"));
		models.add(new Developper("Mourad", "Maatoug", "mr.maatoug@gmail.com",
				"Etudiant"));
		models.add(new Developper("Amine", "Zaafouri",
				"zaafouri.amine@gmail.com", "Etudiant"));
		models.add(new Developper("Iheb", "Maalaoui",
				"iheb.maalaoui@gmail.com", "Etudiant"));
		models.add(new Developper("Mohamed Anis", "Dhuieb",
				"dhuieb.mohamedanis@gmail.com", "Etudiant"));

		List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
		store.add(models);

		ColumnConfig column = new ColumnConfig();
		column.setId("firstName");
		column.setHeader("Prenom");
		column.setWidth(100);
		column.setRowHeader(true);
		configs.add(column);

		column = new ColumnConfig();
		column.setId("lastName");
		column.setHeader("Nom");
		column.setWidth(100);
		column.setRowHeader(true);
		configs.add(column);

		column = new ColumnConfig();
		column.setId("email");
		column.setHeader("Email");
		column.setWidth(200);
		column.setRowHeader(true);
		configs.add(column);

		column = new ColumnConfig();
		column.setId("occupation");
		column.setHeader("Occupation");
		column.setWidth(150);
		column.setRowHeader(true);
		configs.add(column);

		 cm = new ColumnModel(configs);

		 grid = new Grid<Developper>(store, cm);
		grid.setStyleAttribute("borderTop", "none");
		grid.setBorders(false);
		grid.setStripeRows(true);
		grid.setColumnLines(true);
		grid.setColumnReordering(true);

		ContentPanel cp = new ContentPanel();
		cp.setBodyBorder(true);
		cp.setHeading("GWT Project Developpers");
		cp.setButtonAlign(HorizontalAlignment.CENTER);
		cp.setLayout(new FitLayout());
		cp.getHeader().setIconAltText("Grid Icon");
		cp.setSize(600, 400);

		cp.add(grid);

		add(cp);
		

	}
public static void reConfig(){
		grid.reconfigure(store, cm);
	}
public static Grid<Developper> grid ;
public static ListStore<Developper> store;
public static ColumnModel cm;
}
